package com.da.javatest.leetCode;

import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/16 14:43
 * @description
 */
public class Code690 {
    private int total;
    private List<Employee> employees;

    public int getImportance(List<Employee> employees, int id) {
        this.employees = employees;
        Employee employee = employees.stream().filter(e -> e.id == id).findFirst().orElse(null);
        total += employee.importance;
        getTotal(employee.subordinates);
        return total;
    }

    public void getTotal(List<Integer> ids) {
        for (Employee employee : employees) {
            if (ids.contains(employee.id)) {
                total += employee.importance;
                if (employee.subordinates != null && employee.subordinates.size() != 0) {
                    getTotal(employee.subordinates);
                }
            }

        }

    }
}